package com.sherlockmen.common.dto;

import com.sherlockmen.common.constant.ErrorCodeConstants;
import com.sherlockmen.common.exception.BizException;
import com.sherlockmen.common.exception.ErrorCode;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.io.Serial;
import java.io.Serializable;

/**
 * @author: menhao
 * @description: 公共响应体
 * @date: 2025-03-04 10:37
 **/
@Data
@Accessors(chain = true)
@NoArgsConstructor
@AllArgsConstructor
public class Response implements Serializable {

    @Serial
    private static final long serialVersionUID = 1L;
    /**
     * 响应码
     */
    private String code;
    /**
     * 响应信息
     */
    private String message;
    /**
     * 响应数据
     */
    private Object data;

    public static Response success() {
        return success(null);
    }

    public static Response success(Object data) {
        return new Response(ErrorCodeConstants.SUCCESS.getCode(), ErrorCodeConstants.SUCCESS.getMessage(), data);
    }

    public static Response fail(String code, String message) {
        return new Response(code, message, null);
    }

    public static Response fail(String code, String message,Object data) {
        return new Response(code, message, data);
    }

    public static Response fail(BizException bizException) {
        return new Response(bizException.getCode(), bizException.getMessage(), null);
    }

    public static Response fail(ErrorCode ErrorCode) {
        return new Response(ErrorCode.getCode(), ErrorCode.getMessage(), null);
    }
}
